//
// Created by Administrator on 2025/5/28.
//

#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "effective_printf.h"
#include "uart_dma.h"


static uint8_t printf_tx_dma_buf[EFFECTIVE_PRINTF_BUFFER_SIZE] = {0};

int32_t e_printf(const char *format, ...) {
    va_list args;
    int32_t length;

    memset(printf_tx_dma_buf, 0, EFFECTIVE_PRINTF_BUFFER_SIZE);

    va_start(args, format);
    length = vsnprintf((char *) printf_tx_dma_buf, EFFECTIVE_PRINTF_BUFFER_SIZE, format, args);
    va_end(args);

    if (length < 0) {
        return -1;
    }

    uart_dma_tx_send_uart_x(EFFECTIVE_PRINTF_UART, printf_tx_dma_buf, length);
    return length;
}